<?php
/**
 * @Notes:【】
 * @User: zwc
 * @Date: 2022-05-09 0:23
 */

namespace App\Event\Talk;


use App\Dao\User\UserDao;
use Hyperf\Utils\Contracts\Arrayable;

class StartChatEvent implements Arrayable
{
    /**
     * @var int 接收人
     */
    public $friend_id;

    /**
     * @var array 发送人
     */
    public $sender_id;


    public $token;


    /**
     * TalkMessageEvent constructor.
     *
     * @param string $event_name
     * @param array $data
     */
    public function __construct(string $token, $friend_id)
    {
        [$sender_id] = App(\App\Util\JwtAuth::class)->parseToken($token);
        //设置解析token
        $userInfo = App(UserDao::class)->where('uid', $sender_id)->select([
            'avatar', 'nickname'
        ])->first();
        $this->friend_id = $friend_id;
        $this->token = $token;
        $this->sender_id = $sender_id ?? 0;
        $this->avatar = $userInfo->avatar;
        $this->nickname = $userInfo->nickname;
    }

    public function toArray(): array
    {
        return (array)$this;
    }

}